package com.ithema.service.impl;

import com.ithema.entity.Category;
import com.ithema.mapper.CategoryMapper;
import com.ithema.service.CategoryService;
import com.ithema.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;


    @Override
    public void insert(Category category) {
        Map<String, Object> map = ThreadLocalUtil.get();
        category.setCreateUser((int)map.get("userId"));
         categoryMapper.insert(category);
    }

    @Override
    public List<Category> categoryList() {
        Map<String,Object> map = ThreadLocalUtil.get();
        Integer id = (Integer)map.get("userId");
        List<Category> categoryList = categoryMapper.categoryList(id);
        return categoryList;
    }

    @Override
    public Category categoryDetail(Integer id) {
        Category category = categoryMapper.categoryDetail(id);
        return category;
    }

    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }
}
